-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use shards version in crystal init tool #5428
Conversation
I'm against merging |
Hello @RX14, thank you for adding this to I would personally disagree on moving the Cheers. |
@RX14 could you reduce this PR to using |
One nice thing about the lib/project/version.rb in Ruby is that the version file can be loaded independently of the full library if all you want is the version. This is especially used in many .gemspec files. Not sure that applies to Crystal projects or not. |
In my view Additionally it means we don't enforce an opinion between
vs
|
Hello @RX14, thank you for your response. I think you're basing your opinion in comments like this and this? If that is the logic that is driving your change, will be great if you can add those details in the commit message, so future developers will be able to find the logic of that decision. Thank you. |
@Wulfklaue please keep this discussion focused on the PR. You could open a new issue for your comment. |
97ffdc7
to
66104cf
Compare
Updated with a new longer commit message. |
@RX14 The sentence |
It's a typo: directly instead of directory |
66104cf
to
5ad8bdc
Compare
Fixed typo. |
5ad8bdc
to
8245d94
Compare
Rebased to fix travis, hope this can get reviewed. |
# TODO: Write documentation for `<%= module_name %>` | ||
module <%= module_name %> | ||
VERSION = {{ `shards version #{__DIR__}`.chomp.stringify }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't just assume that shards
is available, let alone in PATH. This defeats the whole point of decentralization. Do you really think Crystal libraries should literally not work if shards
is not in PATH?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case it wasn't clear, this literally puts the line VERSION = {{ `shards version #{__DIR__}`.chomp.stringify }}
into all new projects. It's not a dependency of crystal init
, it's a dependency of every library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not particularly fond of hard dependency on shards
either, here it is IMHO justified.
crystal init
is perhaps the first real compiler command run by novice developers following a Crystal tutorial. It should have all batteries included and provide an easy way into the Crystal ecosystem which includes shards
.
The init command is opinionated but dedicated to provide an easy tool for developers to make them happy. If that doesn't fit with specific needs, don't use it. For the vast majority of users this is probably the best thing. And it's good for the ecosystem if people use shards so it doesn't hurt to advocate it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case it wasn't clear, this literally puts the line
VERSION = {{ `shards version #{__DIR__}`.chomp.stringify }}
into all new projects. It's not a dependency ofcrystal init
, it's a dependency of every library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, this is a considerable downside. Maybe a better long-term solution would be to include a simple parser for shards.yml
in the standard library (maybe even directly as a macro method). I've already suggested that idea in #4754 to provide metadata about the project for the docs generator. This way it wouldn't depend on the executable but read shards.yml
directly.
@RX14 With |
I initially thought that this meant That said, I don't know how much time it takes to run, say, 100 or 200 of those shell commands (we should profile this). Maybe it's negligible. I personally don't think keeping the version in |
@asterite this is a macro, surely the constant laziness doesn't apply here? (only runtime) Personally, I've thought about this some more and I think I think a much better system to provide would be to provide Another option is just to generate by default a spec similar to this one. |
I like the idea of simply having a spec for the version. Essentially, it moves reading |
@RX14 What I mean with constant laziness is that the value of constants aren't typed unless used. Try this: ONE = 1 + 'a'
TWO = {{ 1 + 'a' }} it compiles. It's only when you refer to those constants in code that you'll get an error. |
@asterite I wouldn't have thought that that worked with macros, I would have assumed that {% begin %}
TWO = {{ 1 + 'a' }}
{% end %} I thought macros are always done in a pass before we even know which constants are used, so they'd just be evaluated all the time. I understand that Appears i'm incorrect. |
`shards version` is a new shards command which finds a `shard.yml` in the directory tree above the path given and returns the version specified in it. We can use it here to automatically generate the version constant for libraries directly from shard.yml, meaning it will never be out of sync. The `VERSION` constant is also moved into the main library file, instead of being placed in a separate `version.cr`. The old `version.cr` convention persisted from ruby due to the need for gemspec files to require only the version constant from the library.
8245d94
to
8fbe24f
Compare
Rebased onto master to fix merge conflict. Anything left to do here if this doesn't pose a performance impact? |
Relying on subprocesses at compile time is bad. |
Yeah I think we should rather keep it as is for now instead of introducing a feature into potentially many libraries that might prove to pose more trouble than anything. I think it would be more feasible if the compiler would read the data directly from the But I like the idea of removing the extra file for the version constant. |
Can't we just use a makeshift "YAML parser" like this? File.read_lines("#{__DIR__}/../shard.yml").find(&.starts_with?("version:")).try &.byte_slice(8).partition('#')[0].delete(%("')).strip Maybe put in a method |
I'll vote to close: as said in my comment, moving |
@j8r that's a different path and probably a good idea, but both changes are not mutually exclusive. It doesn't make a difference if the file is created by |
It seems this got stalled on a dispute on whether we should make all new projects generated with While one could argue that's already the case as soon as you add a single dependency, I can see the point. Given this doesn't seem to really fix a pain point as evidenced by the lack of discussion and voting on this and no issues referencing this, I'll close this for now. |
Use the
shards version
command introduced by crystal-lang/shards#148 to populate theVERSION
constant inside generated projects withcrystal init
.I moved the
VERSION
constant into the main "example.cr" file, instead of aversion.cr
file too. I guess that will be a divisive change, but I don't think a seperateversion.cr
gains us anything.